import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:sports_new/widgets/base/qkd_text.dart';
import 'package:sports_new/widgets/max_bottom_sheet.dart';
import '../../../controller/service/config_service.dart';
import '../../../resources/colours.dart';

class LiveSettingSheet extends StatefulWidget {
  const LiveSettingSheet({super.key});

  @override
  State<LiveSettingSheet> createState() => _LiveSettingSheetState();
}

class _LiveSettingSheetState extends State<LiveSettingSheet> {
  ConfigService configService = Get.find<ConfigService>();
  PushConfig pushConfig = Get.find<ConfigService>().pushConfig;

  @override
  Widget build(BuildContext context) {
    return MaxBottomSheet(
      onClosing: (){},
      shape: const RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(16))
      ),
      backgroundColor: Colours.white,
      clipBehavior: Clip.antiAlias,
      builder: (context) => Padding(
        padding: const EdgeInsets.fromLTRB(16, 16, 16, 0),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const QkdText("播放器设置",fontSize: 16,fontWeight: FontWeight.w500),
            Row(
              children: [
                const QkdText(
                  "后台播放(应用退至后台,可继续播放声音)",
                  color: Colours.grey66
                ),
                const Spacer(),
                Transform.scale(
                  scale: 0.8,
                  child: CupertinoSwitch(
                    value: pushConfig.liveBackground == 1,
                    activeColor: Colours.main,
                    onChanged: (value) {
                      pushConfig.liveBackground = value ? 1 : 0;
                      configService.update(
                        ConfigType.liveBackground,
                        pushConfig.liveBackground
                      );
                      setState(() {});
                    },
                  ),
                )
              ],
            ).paddingSymmetric(vertical: 16)
          ],
        ),
      )
    );
  }
}
